var correctRadio , designRadio , degreeRadio;

$(function () {
    $("#first_Content_nav > div").eq(0).click();
    $('#avatar99PreId,#avatar98PreId,#avatar97PreId,#avatar96PreId,#avatar95PreId,#avatar0PreId,' +
        '#avatar1PreId,#avatar2PreId,#avatar3PreId,#avatar4PreId,#avatar5PreId,#avatar6PreId,' +
        '#avatar7PreId,#avatar8PreId,#avatar9PreId,#avatar10PreId,#avatar11PreId,#avatar12PreId,' +
        '#avatar13PreId,#avatar14PreId,#avatar15PreId,#avatar16PreId,#avatar17PreId,#avatar18PreId,' +
        '#avatar19PreId,#avatar20PreId,#avatar21PreId,#avatar22PreId,#avatar50PreId').Magnify({
        Toolbar: ['prev', 'next', 'rotateLeft', 'rotateRight', 'zoomIn', 'actualSize', 'zoomOut'],
        keyboard:true, draggable:true, movable:true, modalSize:[1100,700],
        beforeOpen:function (obj,data) {}, opened:function (obj,data) {},
        beforeClose:function (obj,data) {}, closed:function (obj,data) {},
        beforeChange:function (obj,data) {}, changed:function (obj,data) {}
    });
    if($("#doctorValue").val() === 'doctor'){
        $(".span-Scoring,.hideBtn,.scoringInput,.correctDesign,.degreeBox").hide();
    }else {
        if($("#expertComment1").val() !== ""){
            $(".correctComment").show();
        }
        if($("#expertComment2").val() !== ""){
            $(".designComment").show();
        }
        if($("#correctRadioValue").val() !== ""){
            $("[name='correct']:radio[value='"+$("#correctRadioValue").val()+"']").attr('checked','true');
        }
        if($("#designRadioValue").val() !== ""){
            $("[name='design']:radio[value='"+$("#designRadioValue").val()+"']").attr('checked','true');
        }
        if($("#degreeRadioValue").val() !== ""){
            $("[name='degree']:radio[value='"+$("#degreeRadioValue").val()+"']").attr('checked','true');
        }
        if($("#fenStatusValue").val() === "1"){
            $(".correctDesign,.inputBox,#a7").attr('disabled','disabled');
        }
    }
    $(".cp_img_delete").hide();
});


$("#first_Content_nav > div").click(function () {
    var index = $(this).index();
    $(this).addClass('selection').siblings().removeClass('selection');
    $("#first_Content_con > div").eq(index).show().siblings().hide();
    $('.inputComment').each(function () {
        this.setAttribute('style', 'height:' + (this.scrollHeight) + 'px;overflow-y:hidden;');
    }).on('input', function () {
        this.style.height = '32px';
        this.style.height = (this.scrollHeight) + 'px';
    });
});

function firstClose() {
    parent.layer.close(parent.layer.getFrameIndex(window.name));
}

function correctSchemeTitle(obj) {
    var correct = $(obj).val();
    correctRadio = $(obj).val();
    if(correct === '5' || correct === "10" || correct === "0"){
        $(".correctComment").show()
    }else {
        $(".correctComment").hide()
    }
    scoringInput()
}

function designSchemeTitle(obj) {
    var design = $(obj).val();
    designRadio = $(obj).val();
    if(design === '20' || design === "10" || design === "0"){
        $(".designComment").show()
    }else {
        $(".designComment").hide()
    }
    scoringInput()
}

function degreeSchemeTitle(obj) {
    degreeRadio = $(obj).val();
}

function decimalNum(obj) {
    obj.value = obj.value.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
    obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字
    obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个, 清除多余的
    obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
    obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d).*$/, '$1$2.$3'); //只能输入两个小数
    if (obj.value.indexOf(".") < 0 && obj.value != "") {//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
        obj.value = parseFloat(obj.value);
    }
}

function scoringInput() {
    var scoring = 0;
    $(".seven .scoringInput").each(function (index, obj) {
        if($(obj).val() == ""){
            scoring += 0;
        }else {
            scoring += parseFloat($(obj).val());
        }
    });
    if($("input:radio[name='correct']:checked").val() == null || $("input:radio[name='correct']:checked").val() == undefined){
        scoring += 0;
    }else {
        scoring += parseFloat($("input:radio[name='correct']:checked").val());
    }
    if($("input:radio[name='design']:checked").val() == null || $("input:radio[name='design']:checked").val() == undefined){
        scoring += 0;
    }else {
        scoring += parseFloat($("input:radio[name='design']:checked").val());
    }
    $("#a7").val(scoring);
}


function storageOrthodontics() {
    var reservationsId=document.getElementById("reservationsId").value;
    var num=document.getElementById("num").value;
    var a1 = $("#a1").val();
    var a2 = $("#a2").val();
    var a3 = $("#a3").val();
    var a4 = $("#a4").val();
    var a5 = $("#a5").val();
    var a6 = $("#a6").val();
    var a7 = $("#a7").val();
    var C1 = $("#C1").val();
    var C2 = $("#C2").val();
    var C3 = $("#C3").val();
    var C4 = $("#C4").val();
    var expertComment1 = $("#expertComment1").val();
    var expertComment2 = $("#expertComment2").val();
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/orthodonticScoring",
        type: "post",
        data: {
            "reservationsId": reservationsId,
            "num": num,
            "a1": a1,
            "a2": a2,
            "a3": a3,
            "a4": a4,
            "a5": a5,
            "a6": a6,
            "a7": a7,
            "expertComment1":expertComment1,
            "expertComment2":expertComment2,
            "C1": C1,
            "C2": C2,
            "C3": C3,
            "C4": C4,
            "C5": correctRadio,
            "C6": designRadio,
            "degreeRadio":degreeRadio
        },
        success: function (data) {
            Feng.success('操作成功!');
            window.parent.QualityAssurances.table.refresh();
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        }
    })
}

function subOrthodontics() {
    var reservationsId=document.getElementById("reservationsId").value;
    var num=document.getElementById("num").value;
    var a1 = $("#a1").val();
    var a2 = $("#a2").val();
    var a3 = $("#a3").val();
    var a4 = $("#a4").val();
    var a5 = $("#a5").val();
    var a6 = $("#a6").val();
    var a7 = $("#a7").val();
    var C1 = $("#C1").val();
    var C2 = $("#C2").val();
    var C3 = $("#C3").val();
    var C4 = $("#C4").val();
    var expertComment1 = $("#expertComment1").val();
    var expertComment2 = $("#expertComment2").val();
    if(a1===null || a1==="" || a1===undefined){
        alert("请输入纸质病历打分");
        return false;
    }
    if(a2===null || a2==="" || a2===undefined){
        alert("请输入口内照片打分");
        return false;
    }
    if(a3===null || a3==="" || a3===undefined){
        alert("请输入面型照片");
        return false;
    }
    if(a4===null || a4==="" || a4===undefined){
        alert("请输入X线照片打分");
        return false;
    }
    if(a5===null || a5==="" || a5===undefined){
        alert("请输入模型照片打分");
        return false;
    }
    if(a6===null || a6==="" || a6===undefined){
        alert("请输入口内托槽");
        return false;
    }
    if(a7===null || a7==="" || a7===undefined){
        alert("请输入医患沟通方案打分");
        return false;
    }
    if(degreeRadio === undefined){
        alert("请勾选下方难易程度！");
        return false;
    }
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/subCore",
        type: "post",
        data: {
            "reservationsId": reservationsId,
            "num": num,
            "a1": a1,
            "a2": a2,
            "a3": a3,
            "a4": a4,
            "a5": a5,
            "a6": a6,
            "a7": a7,
            "expertComment1":expertComment1,
            "expertComment2":expertComment2,
            "C1": C1,
            "C2": C2,
            "C3": C3,
            "C4": C4,
            "C5": correctRadio,
            "C6": designRadio,
            "degreeRadio":degreeRadio
        },
        success: function (data) {
            Feng.success('操作成功!');
            window.parent.QualityAssurances.table.refresh();
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        }
    })
}
